:- module(_, [term_desc/3,term_desc_keys/3], []).

:- use_module(db(database_impl)).
:- use_module(db(dictionary_access)).
:- use_module(db(basic_types),[null/1]).
:- use_module(library(aggregates),[bagof/3]).

term_desc(Term,Desc,Generalizations):-
	retrieve(Key,ditem(Key,Term,Desc)),
	ditem_generalizations(Key,Generalizations).


term_desc_keys(TermKey,Desc,GeneralizationsKeys):-
	retrieve(TermKey,ditem(TermKey,_Term,Desc)),
	ditem_generalizations_keys(TermKey,GeneralizationsKeys).


ditem_generalizations(Key,List):-
	    bagof(Entry,Definition^ItemKey^(
					 retrieve(generalizations(Key,ItemKey)),
					 retrieve(ItemKey,ditem(ItemKey,Entry,Definition))
						 ),List), !.
ditem_generalizations(_Key,[]):- !.

ditem_generalizations_keys(Key,List):-
	    bagof(ItemKey,retrieve(generalizations(Key,ItemKey)),List), !.
ditem_generalizations_keys(_Key,[]):- !.









